<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>待我审核</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/layuiadmin/style/admin.css" media="all">
</head>
<body>

<div class="layui-card layadmin-header">
    <div class="layui-breadcrumb" lay-filter="breadcrumb">
        <a lay-href="">主页</a>
        <a><cite>组件</cite></a>
        <a><cite>数据表格</cite></a>
        <a><cite>开启分页</cite></a>
    </div>
</div>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">待我审核</div>
                <div class="layui-card-body">
                    <div>
                        <form action="" style="margin-bottom: 10px" id="queryForm" class="layui-form">
                            <div class="layui-row layui-col-space10">
                                <div class="layui-col-md1">
                                    <input type="text" name="name" placeholder="姓名"
                                           class="layui-input">
                                </div>
                                <div class="layui-col-md1">
                                    <input type="text" name="sn" placeholder="学号"
                                           class="layui-input">
                                </div>
                                <div class="layui-col-md1">
                                        <select lay-filter="collegeSn" name="collegeSn" id="collegeSn">
                                            <option value="">选择学院</option>
                                        </select>
                                </div>
                                <div class="layui-col-md1">
                                    <select lay-filter="majorSn" name="majorSn" id="majorSn">
                                        <option value="">选择专业</option>
                                    </select>
                                </div>
                                <div class="layui-col-md1">
                                    <select lay-filter="classSn" name="classSn" id="classSn">
                                        <option value="">选择班级</option>
                                    </select>
                                </div>
                                <div class="layui-col-md3">
                                    <button type="button" class="layui-btn layui-btn-normal" lay-submit=""
                                            lay-filter="appQuery">查询
                                    </button>
                                </div>
                            </div>
                        </form>
                    </div>
                    <table class="layui-hide" id="waitAudit" lay-filter="waitAudit"></table>
                </div>
            </div>
        </div>
    </div>
</div>
<!--性别模板-->
<script id="sex" type="text/html">
    {{# if(d.gender == 'M'){ }}
    <span>男</span>
    {{# }else{  }}
    <span>女</span>
    {{# }  }}
</script>
<!--表头工具栏模板-->
<script id="tableHeadTool" type="text/html">
    <button type="button" class="layui-btn layui-btn-normal" lay-event="audits">批量审核</button>
</script>
<!--列工具栏模板-->
<script id="colTool" type="text/html">
    <button class="layui-btn layui-btn-normal layui-btn-sm" lay-event="audit">审核</button>
</script>
<script src="/layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table', 'laydate'], function () {
        var admin = layui.admin
            , table = layui.table,
            form = layui.form,
            $ = layui.$,
            laydate = layui.laydate
        //渲染表格
        table.render({
            elem: '#waitAudit',
            url: "/application/wait-audit",
            request: {
                pageName: 'pageNo' //页码的参数名称，默认：page
                , limitName: 'pageSize' //每页数据量的参数名，默认：limit
            },
            parseData: function (res) {
                //这里的res就是后端返回的数据
                return {
                    code: res.code,
                    msg: res.message,
                    count: res.data.total,
                    data: res.data.records
                }
            },
            toolbar: "#tableHeadTool",
            cols: [
                [
                    {type: 'checkbox'},
                    {field: 'name', title: '学生姓名'}
                    , {field: 'sex', title: '性别',templet: "#sex"}
                    , {field: 'applyDate', title: '申请时间'}
                    , {field: 'collegeName', title: '学院'}
                    , {field: 'majorName', title: '专业'}
                    , {field: 'className', title: '班级'}
                    , {field: 'difficultyValue', title: '困难等级级别'}
                    , {field: 'nodeName', title: '当前节点'}
                    , {field: 'statusValue', title: '状态'},
                    {fixed: 'right', title: '操作', toolbar: '#colTool'}
                ]
            ],
            page: true,
            limit: 10,
            limits: [10, 20, 40, 100]
        });
        //表头工具栏事件绑定 小括号内的值是表格的lay-filter值
        table.on('toolbar(waitAudit)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            switch (obj.event) {
                case 'audits':
                    auditsEvent()
                    break
            }
        });
        //点击批量审核
        var appIds = []
        function auditsEvent(){
            var checkStatus = table.checkStatus('waitAudit');
            if(checkStatus.data.length == 0){
                layer.msg("请至少选择一条数据",{icon: 6})
                return false
            }
            $("#curNode-audits").val(checkStatus.data[0].currentNodeCode)
            appIds = []
            $(checkStatus.data).each(function (index, item) {
                appIds.push(item.id)
            })
            layer.open({
                type: 1,
                area: '500px',
                content: $("#auditsForm")
            })
        }
        //点击查询
        form.on('submit(appQuery)', function (obj) {
            console.info(obj.field)
            table.reload("waitAudit", {
                url: "/application/wait-audit",
                where: obj.field
            })
        })

        //绑定行工具事件
        table.on("tool(waitAudit)", function (obj) {
            var data = obj.data;//这是点击的这一行的数据
            switch (obj.event) {
                case 'audit':
                    openAuditEvent(data)
                    break;
            }
        })
        //点击审核按钮
        function  openAuditEvent(data) {
            $("#appid").val(data.id)
            $("#curNode").val(data.currentNodeCode)
            layer.open({
                type: 1,
                area: '500px',
                content: $("#auditForm")
            })
        }
        //审核结果提交
        form.on("submit(audit)",function (obj) {
            console.info(obj.field)
            $.ajax({
                type: 'post',
                url: '/application/audit',
                data:obj.field,
                success: function (res) {
                    layer.msg("审核成功",{icon: 6,time: 1500},function () {
                        layer.closeAll()
                        table.reload("waitAudit", {
                            url: "/application/wait-audit"
                        })
                    })
                }
            })
            return false
        })
        //批量审核结果提交
        form.on("submit(audits)",function (obj) {
            obj.field.applicationIds = appIds
            console.info(obj.field)
            $.ajax({
                type: 'post',
                url: '/application/audits',
                data:obj.field,
                success: function (res) {
                    layer.msg("审核成功",{icon: 6,time: 1500},function () {
                        //记得加layer.load()
                        layer.closeAll()
                        table.reload("waitAudit", {
                            url: "/application/wait-audit"
                        })
                    })
                }
            })
            return false
        })
        //弹框取消按钮
        $(".closeAudit").click(function () {
            layer.closeAll()
        })

        /*加载所有学院*/
        $.ajax({
            type: 'get',
            url: '/organizationLevel/list?type=1',
            success: function (res) {
                $(res.data).each(function (index, item) {
                    var $option = $("<option value='"+item.sn+"'name='"+item.organizationId+"'>"+item.organizationName+"</option>")
                    $("#collegeSn").append($option)
                })
                form.render("select")
            }
        })
        //修改学院选择
        form.on("select(collegeSn)",function (obj) {
            console.info(obj)
            console.info($(this))
            var collegeSn = obj.value
            if(collegeSn==''){
                return false
            }
            $.ajax({
                type: 'get',
                url: '/organizationLevel/list?type=2&sn='+collegeSn,
                success: function (res) {
                    $("#majorSn").empty()
                    $("#classSn").empty()
                    form.render("select")
                    $("#majorSn").append('<option value="">选择专业</option>')
                    $("#classSn").append('<option value="">选择班级</option>')
                    $(res.data).each(function (index, item) {
                        var $option = $("<option value='"+item.sn+"' name='"+item.organizationId+"'>"+item.organizationName+"</option>")
                        $("#majorSn").append($option)
                    })
                    form.render("select")
                }
            })
            return false
        })

        //修改专业
        form.on("select(majorSn)",function (obj) {
            var majorSn = obj.value
            if(majorSn == ''){
                return false
            }
            $.ajax({
                type: 'get',
                url: '/organizationLevel/list?type=4&sn='+majorSn,
                success: function (res) {
                    $("#classSn").empty()
                    form.render("select")
                    $("#classSn").append('<option value="">选择班级</option>')
                    $(res.data).each(function (index, item) {
                        var $option = $("<option value='"+item.sn+"' name='"+item.organizationId+"'>"+item.organizationName+"</option>")
                        $("#classSn").append($option)
                    })
                    form.render("select")
                }
            })
            return false
        })
    });
</script>
</body>
<!--单个审核弹框-->
<form id="auditForm" style="display: none;margin-right: 30px;margin-top: 15px" class="layui-form" action="">
    <div class="layui-form-item">
        <input type="hidden" id="appid" name="applicationId">
        <input type="hidden" id="curNode" name="auditNodeCode">
        <label class="layui-form-label">审核结果</label>
        <div class="layui-input-block">
            <select name="status" lay-filter="aihao">
                <option value="TG">通过</option>
                <option value="BTG">不通过</option>
                <!--<option value="TSKN">特殊困难</option>-->
            </select>
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">审核意见</label>
        <div class="layui-input-block">
                        <textarea name="auditComment" class="layui-textarea" id="description"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="button" class="layui-btn" lay-submit="" lay-filter="audit">提交</button>
            <button type="button" class="layui-btn layui-btn-primary closeAudit">取消</button>
        </div>
    </div>
</form>
<!--批量审核弹框-->
<form id="auditsForm" style="display: none;margin-right: 30px;margin-top: 15px" class="layui-form" action="">
    <div class="layui-form-item">
        <input type="hidden" id="curNode-audits" name="auditNodeCode">
        <label class="layui-form-label">审核结果</label>
        <div class="layui-input-block">
            <select name="status" lay-filter="aihao">
                <option value="TG">通过</option>
                <option value="BTG">不通过</option>
                <!--<option value="TSKN">特殊困难</option>-->
            </select>
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">审核意见</label>
        <div class="layui-input-block">
            <textarea name="auditComment" class="layui-textarea"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="button" class="layui-btn" lay-submit="" lay-filter="audits">提交</button>
            <button type="button" class="layui-btn layui-btn-primary closeAudit">取消</button>
        </div>
    </div>
</form>

</html>